const baseUrl = 'http://develop.shangweifw.cn'
const apiUrl = 'https://shop.jufengnr.net/gateway-feature/api'   
const apiUrlJF = 'https://shop.jufengnr.net'
var jf = 'https://kxyhq.kdk59.top'   
   
const request = (urlType= '', url = '', type = '', date = {}, header = {
}) => {
	var that = this
	if(JSON.stringify(header)=='{}'){
		header={
			'Content-type': 'application/json',
			'token': uni.getStorageSync('token')
			
		}
	}
    return new Promise((resolve, reject) => {
		uni.showLoading({
		    title: '获取中...'
		});
        uni.request({
            method: type,
            url: jf + url,
            data: date,
            header: header,
            dataType: 'json'         
        }).then((response) => {
			uni.hideLoading();
			// console.log(response)
			if (response[1].data.status == 0) {
				uni.showToast({
				    title: response[1].data.msg,
					icon: 'error',
				    duration: 2000
				});
				let [error, res] = response;
				resolve(res.data);
			} else if (response[1].data.status == 2) {
				uni.showToast({
				    title: '请先登录',
					icon: 'error',
				    duration: 2000,
					success: () => {
						setTimeout(function () {
							uni.navigateTo({
								url:'/pages/login/index'
							})
						}, 2000);
					}
				});
			} else {
				let [error, res] = response;
				resolve(res.data);
			}
        }).catch(error => {
            let [err, res] = error;
            reject(err)
			console.log(error[1].data)
			uni.showToast({
			    title: error,
				icon: 'none',
			    duration: 2000
			});
        })
    });
	
}
export default request